package ATMAgain;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TransMoneyFrame extends JFrame {

    ICodeService service = new CodeServiceImpl();
    MyJText transCount = new MyJText("汇款账号",20,50,this);
    MyJText transMon = new MyJText("金额",20,100,this);

    public TransMoneyFrame(){
        this.setLayout(null);

        this.init();

        this.setSize(500,300);
        this.setVisible(true);
        this.setDefaultCloseOperation(3);
        this.setLocationRelativeTo(null);
    }

    private void init(){
        MyButton transButton = new MyButton("转账",350,200,this);
        transButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                trans();
            }
        });
    }

    private void trans(){
        String str = service.transMoney(transCount.getText(),Integer.parseInt(transMon.getText()));
        if (str!=null){
            JOptionPane.showMessageDialog(null,str);
        }else {
            TransMoneyFrame.this.dispose();
            new FindFrame();
        }

    }

}
